/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package excom;


import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.table.TableColumn;

/**
 *
 * @author chanhpm
 */
public abstract class JBox extends JPanel {

    
    public JBox(){
        super();
        this.setLayout(new GridLayout(6,1));
        this.setBackground(Color.white);
    }

    public void addJBoxListener(JBoxEventListener mel) {
       listenerList.add(JBoxEventListener.class, mel);
    }

    public void removeJBoxListener(JBoxEventListener mel) {
        listenerList.remove(JBoxEventListener.class, mel);
    }
    
    public void addJBoxEvent(JBoxEvent be){
        Object[] listeners = listenerList.getListenerList();
        for(int i = 0; i < listeners.length; i+= 2)
            if(listeners[i] == JBoxEventListener.class)
                ((JBoxEventListener)listeners[i+1]).myJBoxEvent(be);
    }

    public JButton createBarButton(String name, Icon icon){
            JButton btn = new JButton(name, icon);
            btn.setBorderPainted(false);
            btn.setFocusPainted(false);
            btn.setBackground(Color.WHITE);
            btn.setFont( new Font("Arial",Font.BOLD,13));
            btn.setName(name);

            return btn;
        }

     public JButton createBarButton(String name){
            JButton btn = new JButton(name);
            btn.setBorderPainted(false);
            btn.setFocusPainted(false);
            btn.setBackground(Color.WHITE);
            btn.setFont( new Font("Arial",Font.BOLD,13));
            btn.setName(name);
            return btn;
        }
     public void fireJBoxEvent(final JComponent jcom){
         jcom.addMouseListener(new MouseAdapter() {
            @Override
             public void mouseClicked(MouseEvent e){
               // JOptionPane.showConfirmDialog(null,"abc","abc",JOptionPane.PLAIN_MESSAGE);
                addJBoxEvent(new JBoxEvent(jcom, jcom.getName()));
            }
         });
     }
    
}
